package com.sinosoft.dsp.platform.components.system;

import java.io.Serializable;

import org.primefaces.event.CloseEvent;
import org.primefaces.event.ToggleEvent;

import com.sinosoft.dsp.platform.components.AbstractViewBean;
import com.sinosoft.dsp.platform.services.PlatformViewService;
import com.sinosoft.dsp.platform.utils.MessageBundles;
import com.sinosoft.dsp.platform.utils.SinoManagedBean;
import com.sinosoft.dsp.system.core.exception.SinoException;
import com.sinosoft.dsp.system.utils.Const;

/**
 * 主页面模块视图
 * 
 * @since 1.0 2010-4-26
 * @author 潘巍（Peter Pan）
 * 
 */
public class ModuleBean extends AbstractViewBean implements Serializable,
		IModuleBean {

	private static final long serialVersionUID = -5659005951662665342L;

	public static final String MODULE_ID = "moduleId";
	public static final String EXPANDED = "expanded";
	public static final String AUTO_UPDATE = "autoUpdate";
	public static final String CLOSABLE = "closable";
	public static final String LABEL = "label";
	public static final String IMAGE16 = "image16";

	private String moduleId;

	private boolean expanded;

	private boolean autoUpdate;

	private boolean closable;

	private int row;

	private int column;

	private String label;

	private String image16;

	@Override
	public void construct(String sceneId, String layout) throws SinoException {
		super.construct(sceneId, layout);
		PlatformViewService pvs = SinoManagedBean
				.findBean("platformViewService");
		this.image16 = Const.DEFAULT_IMAGE16;
		this.moduleId = pvs.getAttributeValueFromLayout(super.getLayout(),
				MODULE_ID);
		String expandedStr = pvs.getAttributeValueFromLayout(super.getLayout(),
				EXPANDED);
		this.expanded = (Const.isEmpty(expandedStr)) ? true : Boolean
				.valueOf(expandedStr);
		String autoUpdateStr = pvs.getAttributeValueFromLayout(super
				.getLayout(), EXPANDED);
		this.autoUpdate = (Const.isEmpty(autoUpdateStr)) ? false : Boolean
				.valueOf(autoUpdateStr);
		String closableStr = pvs.getAttributeValueFromLayout(super.getLayout(),
				CLOSABLE);
		this.closable = (Const.isEmpty(closableStr)) ? true : Boolean
				.valueOf(closableStr);

		MessageBundles mb = SinoManagedBean.findBean("messageBundles");
		this.label = pvs.getAttributeValueFromLayout(super.getLayout(), LABEL);
		this.label = (Const.isEmpty(this.label)) ? mb
				.getValue("portal.homeSet.defaultModuleHeader") : this.label;

		this.image16 = pvs.getAttributeValueFromLayout(getLayout(), IMAGE16);
		this.image16 = (Const.isEmpty(this.image16)) ? Const.DEFAULT_IMAGE16
				: this.image16;

	}

	/**
	 * 关闭事件操作
	 */
	@Override
	public void handleClose(CloseEvent event) {

	}

	/**
	 * 开闭事件操作
	 */
	@Override
	public void handleToggle(ToggleEvent event) {

	}

	/**
	 * 刷新事件操作
	 */
	@Override
	public void handleFlush() {

	}

	@Override
	public boolean isExpanded() {
		return expanded;
	}

	@Override
	public void setExpanded(boolean expanded) {
		this.expanded = expanded;
	}

	@Override
	public boolean isAutoUpdate() {
		return autoUpdate;
	}

	@Override
	public void setAutoUpdate(boolean autoUpdate) {
		this.autoUpdate = autoUpdate;
	}

	@Override
	public int getRow() {
		return row;
	}

	@Override
	public void setRow(int row) {
		this.row = row;
	}

	@Override
	public int getColumn() {
		return column;
	}

	@Override
	public void setColumn(int column) {
		this.column = column;
	}

	@Override
	public String getLabel() {
		return label;
	}

	@Override
	public void setLabel(String label) {
		this.label = label;
	}

	@Override
	public String getImage16() {
		return image16;
	}

	@Override
	public void setImage16(String image16) {
		this.image16 = image16;
	}

	@Override
	public String getModuleId() {
		return moduleId;
	}

	@Override
	public void setModuleId(String moduleId) {
		this.moduleId = moduleId;
	}

	@Override
	public boolean isClosable() {
		return closable;
	}

	@Override
	public void setClosable(boolean closable) {
		this.closable = closable;
	}

}
